﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _76超市收银系统
{
    class ShouYin
    {
        //创建仓库对象
        ChanKu ck = new ChanKu();
        /// <summary>
        /// 创建超市对象的时候，给仓库的货架上导入货物
        /// </summary>
        public ShouYin()
        {
            ck.JinPros("Acer", 1000);
            ck.JinPros("SanXing", 1000);
            ck.JinPros("JiangYou", 1000);
            ck.JinPros("Banana",1000);
        }

        public void HuDong()
        {
            Console.WriteLine("欢迎光临，请问你需要什么?");
            Console.WriteLine("我们有宏基笔记本，三星手机，老抽酱油，香蕉");
            string strType = Console.ReadLine();
            Console.WriteLine("你需要多？");
            int count = Convert.ToInt32(Console.ReadLine());
            //去仓库去货物
            FuLei[] pros = ck.GetPros(strType, count);
            //计算价格
            double Money = GetMoney(pros);
            Console.WriteLine("你总共应付{0}元",Money);
            Console.WriteLine("请选择你的付款方式 1--不打折 2--九折 3--85折 4--买300送50 5--买500送100");
            string input = Console.ReadLine();
            //通过简单工厂的设计根据用户的输入获得折扣对象
            CalFather cal = GetCal(input);
            double totalMoney = cal.GetToMoney(Money);
            Console.WriteLine("打完折后你应付{0}元",totalMoney);
        }

        /// <summary>
        /// 根据用户选择的打折方式返回一个打折对象
        /// </summary>
        /// <param name="input">用户的选择</param>
        /// <returns>返回的父类对象 但是里面装着的是子类对象</returns>
        public CalFather GetCal(string input)
        {
            CalFather cal = null;
            switch (input)
            {
                case "1":new CalNoZhe();
                    break;
                case "2":new CalRate(0.9);
                    break;
                case "3":new CalRate(0.85);
                    break;
                case "4":new CalMN(300, 50);
                    break;
                case "5":new CalMN(500, 100);
                    break;
            }
            return cal;
        }


        /// <summary>
        /// 根据用户买的货物计算总价钱
        /// </summary>
        /// <param name="pros"></param>
        /// <returns></returns>
        public double GetMoney(FuLei[] pros)
        {
            double Money = 0;
            for (int i = 0; i < pros.Length; i++)
            {
                Money += pros[i].Price;
            }
            return Money;
        }
     

        public void Shou()
        {
            ck.Shou();
        }
    }
}
